# -*- coding: utf-8 -*-

import json

from task import Task


class RecruitmentTaskProducer(Task):

    def _init(self):
        super(RecruitmentTaskProducer, self)._init()

        self.__conveyor = self._components['conveyor']
        self.__sqle = self._components['sqlexecutor']

    def begin(self):
        self.__sqle.reset()
        self.__sqle.sql = "SELECT company_name FROM recruitment_monitor_company"
        retList = self.__sqle.execute_dataset()
        for item in retList:
            ret = self.__conveyor.send(json.dumps({
                'companyName': item.get('company_name',''),
                'source': 'lagou',
                'crawlerSource': 'crawler_recruitment_lagou.LagouCrawler'
            }))

            print ret
